package com.hhf.cloud.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * @author Daniel-黄海峰
 * @Description
 * @create 2024/3/2 16:12
 */
@LocalTCC //代表这个service接口需要开启seata的TCC模式
public interface StorageTccService {
    /**
     * 扣减库存
     *
     * @param
     * @param productId 产品id
     * @param count     数量
     * @return
     * @TwoPhaseBusinessAction就等于try预占资源 参数name必须跟service接口方法名一致
     * useTCCFence（默认不开启） seata1.5.1的新特性，用于解决TCC幂等，悬挂，空回滚问题，需增加日志表tcc_fence_log才能开启
     * useTCCFence详细讲解文档地址：https://seata.apache.org/zh-cn/blog/seata-tcc-fence/
     * 这次TCC案例不开启useTCCFence
     */
    @TwoPhaseBusinessAction(name = "decreaseTcc", commitMethod = "commit", rollbackMethod = "rollback", useTCCFence = false)
    boolean decreaseTcc( @BusinessActionContextParameter("productId")Long productId, @BusinessActionContextParameter("count")Integer count);

    /**
     * Confirm 提交事务
     * BusinessActionContext：纳入全局范围的上下文
     * @param actionContext
     * @return
     */
    boolean commit(BusinessActionContext actionContext);

    /**
     * Cancel 回滚事务
     * @param actionContext
     * @return
     */
    boolean rollback(BusinessActionContext actionContext);

}
